<template>
  <div class="container">
    <p>
      orginData：{{orginData}}
    </p>
    <p>
      changeData：{{changeData}}
    </p>
  </div>
</template>

<script>
export default {
  data(){
    return{
      orginData: 28128128128128,
      changeData:''
    }
  },
  created(){
    this.loadData()
  },
  mounted(){
    
  },
  methods:{
    loadData(){
      var num = this.orginData.toString(), re = /\d{3}$/, result = '';
      // RegExp.lastMatch —— 最后匹配到的字符串
      // RegExp.leftContext —— 最新匹配的左侧子串
      while ( re.test(num) ) {
        result = RegExp.lastMatch + result;
        if (num !== RegExp.lastMatch) {
          result = ',' + result;
          num = RegExp.leftContext;
        } else {
          num = '';
          break;
        }
      }
      // 剩下的数字
      if(num){
        result = num + result
      }
      this.changeData = result
    }
  } 
}

</script>
<style>
</style>